import 'dart:io';

import 'package:dio/dio.dart';
import 'package:flutter_roujiaosuo/constants/common_constants.dart';
import 'package:flutter_roujiaosuo/flutter_bloc/requests/models/home_top_model.dart';
import '../dio_util.dart';
import '../models/SupplyModel.dart';

class RoujiaosuoRepository {
  Future<HomeTopModel> getHomeTop() async {
    Map<String, String> map = {'action': 'index'};
    // Response response =
    //     await _dio.get(RoujiaosuoApi.Home_Top, queryParameters: map);
    BaseResp<HomeTopModel> res = await DioUtil().request<HomeTopModel>(
        Method.get,
        RoujiaosuoApi.Home_Top,
        BaseProcessor(false, fun: HomeTopModel.generateOBJ),
        queryParameters: map);
    // HomeTopModel model = HomeTopModel.fromJson(res.data);
    print('----------------------------------');
    print('status: ${res.status}');
    print('code: ${res.code}');
    print('msg: ${res.msg}');
    print('data: ${res.data}');
    print('----------------------------------');
    // BaseResp<HomeTopModel> baseResp = await DioRequestTool()
    //     .request(Method.get, RoujiaosuoApi.Home_Top, data: map);
    // print(baseResp.data);
    HomeTopModel resModel = res.data;
    return resModel;
  }

  Future<Supply> getSupplyList(int page) async {
    page == null ?? 1;
    Map<String, dynamic> params = {'action': 'list', 'page': page};

    BaseRespList<SupplyModel> res = await DioUtil().request<SupplyModel>(
        Method.get,
        RoujiaosuoApi.Supply_List,
        BaseProcessor(true, fun: SupplyModel.generOBJ),
        queryParameters: params);
    Supply resModel = Supply(
        code: res.code, msg: res.msg, data: res.data as List<SupplyModel>);

    return resModel;
  }
  // HomeTopModel homeTopModel =
}
